#include "qconstants.h"
#include "qzodiac.h"


QList<QZodiac> QZodiac::m_zodiacList;


QZodiac::QZodiac(const QString &strName,
    const QString &strNameCN, const QDate &dtBegin, const QDate &dtEnd)
    : m_strName(strName), m_strNameCN(strNameCN), m_dtBegin(dtBegin), m_dtEnd(dtEnd)
{

}

QString QZodiac::name() const
{
    return m_strName;
}

QString QZodiac::nameCN() const
{
    return m_strNameCN;
}

QDate QZodiac::begin() const
{
    return m_dtBegin;
}

QDate QZodiac::end() const
{
    return m_dtEnd;
}

QString QZodiac::toString() const
{

    QString strUpperName = m_strName.at(0).toUpper() + m_strName.mid(1);
    return QString("%1 %2 (%3 - %4)").arg(m_strNameCN, strUpperName, m_dtBegin.toString("MM/dd"), m_dtEnd.toString("MM/dd"));
}

QList<QZodiac> QZodiac::allInstance()
{
    static QString arrNames[] = {
        "Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo",
        "Libra", "Scorpio", "Sagittarius", "Capricorn", "Aquarius", "Pisces" };
    static QDate arrBegin[] = {
        QDate(1, 3, 21), QDate(1, 4, 20), QDate(1, 5, 21), QDate(1, 6, 22), QDate(1, 7, 23), QDate(1, 8, 23),
        QDate(1, 9, 23), QDate(1, 10, 24), QDate(1, 11, 23), QDate(1, 12, 22), QDate(1, 1, 20), QDate(1, 2, 19) };
    static QDate arrEnd[] = {
        QDate(1, 4, 19), QDate(1, 5, 20), QDate(1, 6, 21), QDate(1, 7, 22), QDate(1, 8, 22), QDate(1, 9, 22),
        QDate(1, 10, 23), QDate(1, 11, 22), QDate(1, 12, 21), QDate(1, 1, 19), QDate(1, 2, 18), QDate(1, 3, 20) };

    if (m_zodiacList.isEmpty()) {
        QConstants constants;
        for (int i = 0; i < 12; i++) {
            QString strKey = "ast.zodiac." + arrNames[i].toLower();
            QString strNameCn = constants.value(strKey);
            QZodiac zodiac(arrNames[i], strNameCn, arrBegin[i], arrEnd[i]);
            m_zodiacList << zodiac;
        }
    }
    return m_zodiacList;
}
